package com.aaa.hospital.service.impl;

import com.aaa.hospital.mapper.NewsTypeMapper;
import com.aaa.hospital.pojo.domain.NewsReporter;
import com.aaa.hospital.pojo.domain.NewsType;
import com.aaa.hospital.pojo.query.NewsTypeQuery;
import com.aaa.hospital.pojo.vo.NewsTypeVO;
import com.aaa.hospital.result.AjaxResult;
import com.aaa.hospital.service.NewsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @program:qy888
 * @description:www
 * @author:LJW
 * @version: 1.0
 * @create:2022-2-16 19:39
 */
@Service
public class NewsTypeServiceImpl implements NewsTypeService {
    @Autowired
    private NewsTypeMapper newsTypeMapper;

    @Override
    public AjaxResult list() {

        List<NewsType> newsTypes = newsTypeMapper.listAll();
        return AjaxResult.success(newsTypes);

    }

    @Override
    public AjaxResult leixingsousuo(NewsTypeQuery newsTypeQuery) {

        List<NewsType> newsTypes = newsTypeMapper.newsType(newsTypeQuery);
        Long aLong = newsTypeMapper.newsTypeTotal(newsTypeQuery);
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("currentData",newsTypes);
        objectObjectHashMap.put("totalCountNews",aLong);

        return AjaxResult.success(objectObjectHashMap);
    }

    @Override
    public AjaxResult faburen() {
        List<NewsReporter> newsReporters = newsTypeMapper.faburen();
        return AjaxResult.success(newsReporters);
    }

    @Override
    public AjaxResult add(NewsTypeVO newsTypeVO) {
        NewsType newsType = newsTypeMapper.getname(newsTypeVO);
        if(newsType == null){
            int i =newsTypeMapper.add(newsTypeVO);
            return AjaxResult.success("添加成功");
        }
        return AjaxResult.fail("警告！（重复类型）");
    }

    @Override
    public AjaxResult delete(Integer id) {
        int i = newsTypeMapper.delete(id);
        if (i>1){
            return AjaxResult.success();
        }else {
            return AjaxResult.fail();
        }
    }

    @Override
    public AjaxResult get(Integer id) {
        NewsType t =newsTypeMapper.updateByID(id);
        return AjaxResult.success(t);
    }

    @Override
    public AjaxResult update(NewsTypeVO newsTypeVO) {
        NewsType newsType = newsTypeMapper.getName(newsTypeVO);
        if(newsType == null){
            int i =newsTypeMapper.update(newsTypeVO);
            return AjaxResult.success("修改成功");
        }
        return AjaxResult.fail("警告！（重复类型）");
    }
}

